package com.stm.meet.Controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.fasterxml.jackson.databind.util.JSONWrappedObject;
import com.stm.meet.Entitys.AppData;
import com.stm.meet.Entitys.CardEntity;
import com.stm.meet.Entitys.MeetEntity;
import com.stm.meet.Service.CardService;
import com.stm.meet.Service.MeetService;
import com.stm.meet.Utils.Response;
import jdk.nashorn.internal.parser.JSONParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.smartcardio.Card;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    MeetService meetService;

    @Autowired
    CardService cardService;

    @Autowired
    Response response;

    Logger logger = LoggerFactory.getLogger(IndexController.class);

    @RequestMapping(value = "/getuser/{username}",method = RequestMethod.GET)
    @ResponseBody
    public String getUser(@PathVariable String username, @RequestParam  String password){
        return "welcome ," + username;
    }



    /**
     * TODO:这里接收对象有问题.
     * @param
     * @return
     */
    @RequestMapping(value = "/meet_save",consumes = "application/json",method = RequestMethod.POST)
    @ResponseBody
//    public String saveMeet(@RequestBody MeetEntity meetEntity){
//        meetService.meetSave(meetEntity);
//        logger.info("saveMeet");
//        logger.info("info:"+meetEntity.toString());
//        return meetEntity.toString();
//    }
    public Response saveMeet(@RequestBody AppData data){
        logger.info(data.toString());
        meetService.meetSave(data.getMeet());
        cardService.saveCards(data.getCards());
        return response;
    }



}
